package com.git.dengchongshuang.managementsystem;

import java.util.Random;

public class Captcha {
    private static String UpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static String LowerCase = "abcdefghijklmnopqrstuvwxyz";
    private static String number = "1234567890";
    static Random rand = new Random();

    public static String allCase = UpperCase + LowerCase + number;

    //返回一个随机生产的验证码，形参是要生成验证码的长度
    public static String getCaptcha(int captchaLength){
        StringBuffer ret = new StringBuffer();
        for(int i=0;i<captchaLength;i++){
            int index = rand.nextInt(allCase.length());
            ret.append(allCase.charAt(index));
        }

        return ret.toString();
    }
}
